package com.jy.adscm.operation.mscyb.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.*;
import com.jy.adscm.operation.mscyb.service.JqfzIssueQsService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-06-14
 */
@RestController
@RequestMapping("/adscm/operation/jqfz/jqfzIssueQs")
public class JqfzIssueQsController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    JqfzIssueQsService jqfzIssueQsService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JqfzIssueQs jqfzIssueQs, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        jqfzIssueQs.setTaskreleaseperson(token.getUser().getId().toString());
        jqfzIssueQs.setTaskreleaseaddtime(new Date());
        jqfzIssueQs.setTaskfinishstate(0);
        jqfzIssueQs.setTaskstate(0);
        jqfzIssueQs.setIstaskstart("0");
        jqfzIssueQs.setIstaskbegin("0");
        jqfzIssueQs.setIstaskend("0");
        jqfzIssueQs.setIsreviewtask("0");
        jqfzIssueQs.setReviewresult("-1");
        boolean insert = jqfzIssueQsService.insertJqfzIssueQs(jqfzIssueQs);
        return new SimpleCoreResponse("200","新增成功",insert);
    }

    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id)throws AdscmSystemException {
        boolean result = jqfzIssueQsService.deleteById(id);
        return new SimpleCoreResponse("200","删除成功",result);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody JqfzIssueQs jqfzIssueQs, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result = jqfzIssueQsService.updateJqfzIssueQs(jqfzIssueQs,token);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("selectJqfzIssueQs")
    public  SimpleCoreResponse  selectJqfzIssueQs(@RequestBody QueryJqfzIssueQs queryJqfzIssueQs) throws  AdscmSystemException{
        Page<JqfzIssueQs> page =new Page<>(queryJqfzIssueQs.getCurrentPage(),queryJqfzIssueQs.getPageSize());
        page = jqfzIssueQsService.selectJqfzIssueQs(page,queryJqfzIssueQs);
        return  new SimpleCoreResponse("200","查询成功",page);
    }

    @RequestMapping("selectTaskPerformPerson")
    public  SimpleCoreResponse  selectTaskPerformPerson() throws  AdscmSystemException{
        List<JyUser> users = jqfzIssueQsService.selectTaskPerformPerson();
        return  new SimpleCoreResponse("200","查询成功",users);
    }
    @RequestMapping("selectJqcheckRecoder/{code}")
    public  SimpleCoreResponse  selectJqcheckRecoder(@PathVariable String code) throws  AdscmSystemException{
          List<JqCheckRecoder> jqCheckRecoder =jqfzIssueQsService.selectJqcheckRecoder(code);
        return  new SimpleCoreResponse("200","查询成功",jqCheckRecoder);
    }
    @RequestMapping("selectQcJqcheckRecoder/{code}")
    public  SimpleCoreResponse  selectQcJqcheckRecoder(@PathVariable String code) throws  AdscmSystemException{
          List<JqCheckRecoder> jqCheckRecoder =jqfzIssueQsService.selectQcJqcheckRecoder(code);
        return  new SimpleCoreResponse("200","查询成功",jqCheckRecoder);
    }



    /**
     * 发证查找产品出厂检验
     * @param code
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("selectJqcs/{code}")
    public  SimpleCoreResponse  selectJqcs(@PathVariable String code) throws  AdscmSystemException{
          List<JqcsMachineTest> JqcsMachineTests =jqfzIssueQsService.selectJqcs(code);
        return  new SimpleCoreResponse("200","查询成功",JqcsMachineTests);
    }

    /**
     * 发证查找总装
     * @param code
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("selectJqzz/{code}")
    public  SimpleCoreResponse  selectJqzz(@PathVariable String code) throws  AdscmSystemException{
          List<JqzzMachine> JqcsMachineTests =jqfzIssueQsService.selectJqzz(code);
        return  new SimpleCoreResponse("200","查询成功",JqcsMachineTests);
    }
    /**
     * 发证查找部装
     * @param code
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("selectJqbz/{code}")
    public  SimpleCoreResponse  selectJqbz(@PathVariable String code) throws  AdscmSystemException{
          List<JqbzPartsassembly> JqcsMachineTests =jqfzIssueQsService.selectJqbz(code);
        return  new SimpleCoreResponse("200","查询成功",JqcsMachineTests);
    }



}

